#include<bits/stdc++.h>
using namespace std;
#define lup(var,start,end) for(long long var=start;var<=end;var++)
#define ldn(var,start,end) for(long long var=start;var>=end;var--)
typedef long long ll;
ll read(void);
void write(ll);
int T,n,C[200005],A[200005],jmp[200005],mp[200005],c;
set<ll> eewe;
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    T=read();
    while(T--)
    {
        n=read();
        lup(i,1,n)
        {
            A[i]=read();
            jmp[A[i]]+=1;
            eewe.insert(A[i]);
        }
        for(auto it:eewe){
            c+= *it * jmp[*it];
        }
        write(c);
        c=0;
    }
    return 0;
}
inline ll read(void)
{
    char ch=getchar();
    int input_sign=1;
    long long input_result=0;
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')input_sign=-1;
        ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        input_result=(input_result<<1)+(input_result<<3);
        input_result+=ch^48;
        ch=getchar();
    }
    return input_sign*input_result;
}
inline void write(ll output_value)
{
    if(output_value<0)
    {
        output_value=0-output_value;
        putchar('-');
    }
    if(output_value==0)
    {
        putchar('0');
        return;
    }
    int output_digit[40],output_len=0;
    while(output_value>0)
    {
        output_digit[++output_len]=(output_value%10)^48;
        output_value/=10;
    }
    for(int i=output_len; i>=1; i--)putchar(output_digit[i]);
}
